package restaurant.behaviours.waiter;

import jade.core.behaviours.CyclicBehaviour;
import jade.lang.acl.ACLMessage;
import jade.lang.acl.MessageTemplate;
import restaurant.agents.WaiterAgent;
import restaurant.core.CustomizedPerformative;

public class WaiterAvailableBehaviour extends CyclicBehaviour {
	
	private static final long serialVersionUID = -4921664340524373601L;
	private WaiterAgent agent;
	
	public WaiterAvailableBehaviour(WaiterAgent agent) {
		this.agent = agent;
	}
	
	@Override
	public void action() {
		MessageTemplate messageTemplate = MessageTemplate.MatchPerformative(CustomizedPerformative.AVAILABLE_WAITER);
		ACLMessage message = myAgent.receive(messageTemplate);
		if(message != null) {
			switch (Integer.parseInt(message.getContent())) {
			case CustomizedPerformative.BILL: {
				this.agent.updateExperience();
				
				System.out.println("WaiterAgent: Vado subito al tavolo per portare il conto");
				this.agent.toDo = CustomizedPerformative.BILL;
				this.agent.goalReached = false;
			}
				break;
			case CustomizedPerformative.WAITER_CALLING: {
				this.agent.updateExperience();
				
				System.out.println("WaiterAgent: Vado subito al tavolo per prendere l'ordinazione");
				this.agent.toDo = CustomizedPerformative.WAITER_CALLING;
				this.agent.goalReached = false;
			}
				break;
			case CustomizedPerformative.WAITER_KITCHEN_COMMUNICATION: {
				this.agent.updateExperience();
				
				System.out.println("WaiterAgent: Vado subito a prendere il cibo pronto");
				this.agent.toDo = CustomizedPerformative.WAITER_KITCHEN_COMMUNICATION;
				this.agent.goalReached = false;
			}
				break;
			default:
				break;
			}
			if(!this.agent.isProfessional() && this.agent.getExperience() > this.agent.getMinExperience())
				this.agent.setProfessional(true);
		}
	}

}